home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / HENSA / MATHS / PLPLOT / PLPLOT.ZIP / examples / C / x08c.c < prev    next >
C/C++ Source or Header  |  1994-06-30  |  3KB  |  105 lines

  1. /* $Id: x08c.c,v 1.8 1994/06/30 17:57:37 mjl Exp $
  2.  * $Log: x08c.c,v $
  3.  * Revision 1.8  1994/06/30  17:57:37  mjl
  4.  * All C example programs: made another pass to eliminate warnings when using
  5.  * gcc -Wall.  Lots of cleaning up: got rid of includes of math.h or string.h
  6.  * (now included by plplot.h), eliminated redundant casts, put in more
  7.  * uniform comments, and other minor changes.
  8.  *
  9.  * Revision 1.7  1994/03/30  07:21:52  mjl
  10.  * Changes to all C example programs: special handling for malloc re: header
  11.  * files eliminated, include of stdio.h and stdlib.h eliminated (now done
  12.  * by plplot.h), include of "plplot.h" changed to <plplot.h> to enable
  13.  * simpler builds by the general user, some cleaning up also.
  14. */
  15.  
  16. /*    x08c.c
  17.  
  18.     3-d plot demo.
  19. */
  20.  
  21. #include <plplot.h>
  22.  
  23. #define XPTS    35        /* Data points in x */
  24. #define YPTS    46        /* Datat points in y */
  25.  
  26. static int opt[] =
  27. {1, 2, 3, 3};
  28.  
  29. static PLFLT alt[] =
  30. {60.0, 20.0, 60.0, 60.0};
  31.  
  32. static PLFLT az[] =
  33. {30.0, 60.0, 120.0, 160.0};
  34.  
  35. static char *title[4] =
  36. {
  37.     "#frPLplot Example 8 - Alt=60, Az=30, Opt=1",
  38.     "#frPLplot Example 8 - Alt=20, Az=60, Opt=2",
  39.     "#frPLplot Example 8 - Alt=60, Az=120, Opt=3",
  40.     "#frPLplot Example 8 - Alt=60, Az=160, Opt=3"
  41. };
  42.  
  43. /*----------------------------------------------------------------------*\
  44.  * main
  45.  *
  46.  * Does a series of 3-d plots for a given data set, with different
  47.  * viewing options in each plot.
  48. \*----------------------------------------------------------------------*/
  49.  
  50. int
  51. main(int argc, char *argv[])
  52. {
  53.     int i, j, k;
  54.     PLFLT *x, *y, **z;
  55.     PLFLT xx, yy, r;
  56.  
  57. /* Parse and process command line arguments */
  58.  
  59.     (void) plParseInternalOpts(&argc, argv, PL_PARSE_FULL);
  60.  
  61. /* Initialize plplot */
  62.  
  63.     plinit();
  64.  
  65.     x = (PLFLT *) malloc(XPTS * sizeof(PLFLT));
  66.     y = (PLFLT *) malloc(YPTS * sizeof(PLFLT));
  67.     z = (PLFLT **) malloc(XPTS * sizeof(PLFLT *));
  68.  
  69.     for (i = 0; i < XPTS; i++) {
  70.     z[i] = (PLFLT *) malloc(YPTS * sizeof(PLFLT));
  71.     x[i] = (double) (i - (XPTS / 2)) / (double) (XPTS / 2);
  72.     }
  73.  
  74.     for (i = 0; i < YPTS; i++)
  75.     y[i] = (double) (i - (YPTS / 2)) / (double) (YPTS / 2);
  76.  
  77.     for (i = 0; i < XPTS; i++) {
  78.     xx = x[i];
  79.     for (j = 0; j < YPTS; j++) {
  80.         yy = y[j];
  81.         r = sqrt(xx * xx + yy * yy);
  82.         z[i][j] = exp(-r * r) * cos(2.0 * 3.141592654 * r);
  83.     }
  84.     }
  85.  
  86.     for (k = 0; k < 4; k++) {
  87.     pladv(0);
  88.     plvpor(0.0, 1.0, 0.0, 0.9);
  89.     plwind(-1.0, 1.0, -0.9, 1.1);
  90.     plcol(1);
  91.     plw3d(1.0, 1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, alt[k], az[k]);
  92.     plbox3("bnstu", "x axis", 0.0, 0,
  93.            "bnstu", "y axis", 0.0, 0,
  94.            "bcdmnstuv", "z axis", 0.0, 0);
  95.  
  96.     plcol(2);
  97.     plot3d(x, y, z, XPTS, YPTS, opt[k], 1);
  98.     plcol(3);
  99.     plmtex("t", 1.0, 0.5, 0.5, title[k]);
  100.     }
  101.  
  102.     plend();
  103.     exit(0);
  104. }
  105.